package cn.caipengbo.results;

import cn.dsna.util.images.ValidateCode;
import com.opensymphony.xwork2.ActionInvocation;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.dispatcher.StrutsResultSupport;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;

/**
 * Created by Myth on 2/2/2017.
 */
public class CaptchaResult extends StrutsResultSupport {
    //输出结果
    private int width = 100;
    private int height = 80;
    private int codeCount = 4;
    private int lineCount = 10;
    @Override
    protected void doExecute(String s, ActionInvocation actionInvocation) throws Exception {
        ValidateCode validateCode = new ValidateCode(width,height,codeCount,lineCount);
        BufferedImage image = validateCode.getBuffImg();
        //获得response
        HttpServletResponse response = ServletActionContext.getResponse();
        //输出到 输出流 上
        ImageIO.write(image,"jpeg",response.getOutputStream());
    }
}
